module two {
	export class BaseComponent extends eui.Component implements eui.UIComponent {

		
		private _isClosed : boolean = false;
		public get isClosed() : boolean {
			return this._isClosed;
		}
		public set isClosed(v : boolean) {
			this._isClosed = v;
		}
		
		public constructor(skinName?:string) {
			super();

			this.addEventListener(egret.Event.ADDED_TO_STAGE, (e: egret.Event) => {
				if (e.target == e.currentTarget) {
					this.__isAdded = true;
					if (this.__isCreated) {
						this.addTo();
					}
				}
			}, this);

			if (skinName) {
				if (!skinName.match(/Skin/)) {
					skinName += "Skin";
				}
				this.skinName = skinName;
			}
		}

		private __isAdded: boolean = false;
		private __isCreated: boolean = false;

		protected childrenCreated(): void {
			super.childrenCreated();

			this.addEventListener(egret.Event.REMOVED_FROM_STAGE, (e: egret.Event) => {
				if (e.target == e.currentTarget) {
					this.__isAdded = false;
					this.removed();
				}
			}, this);

			this.__isCreated = true;
			if (this.__isAdded) {
				this.addTo();
			}
		}
		private __isFirstCreated: boolean = true;
		private addTo(): void {
			if (this.__isFirstCreated) {
				this.created();
			}

			this.added();

			if (this.__isFirstCreated) {
				this.createdEnd();
			}
			this.__isFirstCreated = false;
		}

		protected createdEnd():void {

		}

		protected created(): void {

		}

		protected added(): void {

		}
		
		protected removed(): void {

		}

		public refreshApi(api:string):void {

		}

		public refreshData(type:string, data:any):void {

		}
	}
}